package com.tianji.learning.contoller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author : Cammy.Wu
 * Description : 
 */

@Api(tags = "我的课表相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService lessonService;

    @ApiOperation("查询我的课表，排序字段 latest_learnTime:学习时间排序，createTime:购买时间排序")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery query) {
        return lessonService.queryMyLessons(query);
    }

    @ApiOperation("查询我正在学习的课程")
    @GetMapping("/now")
    public LearningLessonVO queryMyCurrentLesson() {
        return lessonService.queryMyCurrentLesson();
    }

    @ApiOperation("删除课程")
    @DeleteMapping("/{courseId}")
    public void deleteMyLessons(@PathVariable Long courseId) {
        // 调用服务层方法删除课程
        lessonService.deleteMyLessons(courseId);
    }

    @ApiOperation("检查课程是否有效")
    @GetMapping("/{courseId}/valid")
    public Long isLessonValid(@PathVariable Long courseId) {
        return lessonService.isLessonValid(courseId);
    }

    /**
     * 创建学习计划
     * @param learningPlanDTO
     */
    @ApiOperation("创建学习计划")
    @PostMapping("/lesson/plans")
    public void createLearningPlan(@Valid @RequestBody LearningPlanDTO learningPlanDTO) {
        lessonService.createLearningPlan(learningPlanDTO.getCourseId(), learningPlanDTO.getFreq());
    }

    /**
     * 查询我的学习计划
     * @param pageQuery
     * @return
     */
    @ApiOperation("查询我的学习计划")
    @GetMapping("/plans")
    public LearningPlanPageVO queryMyPlans(PageQuery pageQuery) {
        return lessonService.queryMyPlans(pageQuery);
    }

}
